from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-24 14:12:07.748318
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 24, Feb, 2021
Time: 14:12:11
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3573
Nobs: 212.000 HQIC: -47.2063
Log likelihood: 2447.59 FPE: 1.77295e-21
AIC: -47.7823 Det(Omega_mle): 1.17096e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.469305 0.136949 3.427 0.001
L1.Burgenland 0.071842 0.070126 1.024 0.306
L1.Kärnten -0.218696 0.059658 -3.666 0.000
L1.Niederösterreich 0.128144 0.160687 0.797 0.425
L1.Oberösterreich 0.257256 0.142910 1.800 0.072
L1.Salzburg 0.216129 0.075826 2.850 0.004
L1.Steiermark 0.098713 0.102278 0.965 0.334
L1.Tirol 0.130982 0.068386 1.915 0.055
L1.Vorarlberg -0.015310 0.062056 -0.247 0.805
L1.Wien -0.123129 0.134140 -0.918 0.359
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.476944 0.164620 2.897 0.004
L1.Burgenland 0.010917 0.084295 0.130 0.897
L1.Kärnten 0.354113 0.071712 4.938 0.000
L1.Niederösterreich 0.110306 0.193154 0.571 0.568
L1.Oberösterreich -0.133838 0.171785 -0.779 0.436
L1.Salzburg 0.197846 0.091146 2.171 0.030
L1.Steiermark 0.206547 0.122943 1.680 0.093
L1.Tirol 0.140132 0.082204 1.705 0.088
L1.Vorarlberg 0.157891 0.074594 2.117 0.034
L1.Wien -0.508039 0.161243 -3.151 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.314034 0.062547 5.021 0.000
L1.Burgenland 0.099324 0.032028 3.101 0.002
L1.Kärnten -0.017938 0.027247 -0.658 0.510
L1.Niederösterreich 0.093453 0.073388 1.273 0.203
L1.Oberösterreich 0.305757 0.065269 4.685 0.000
L1.Salzburg 0.000297 0.034631 0.009 0.993
L1.Steiermark -0.013588 0.046712 -0.291 0.771
L1.Tirol 0.078657 0.031233 2.518 0.012
L1.Vorarlberg 0.101294 0.028342 3.574 0.000
L1.Wien 0.045406 0.061263 0.741 0.459
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220107 0.068586 3.209 0.001
L1.Burgenland -0.004779 0.035120 -0.136 0.892
L1.Kärnten 0.019988 0.029878 0.669 0.503
L1.Niederösterreich 0.042058 0.080474 0.523 0.601
L1.Oberösterreich 0.387723 0.071571 5.417 0.000
L1.Salzburg 0.087324 0.037974 2.300 0.021
L1.Steiermark 0.178641 0.051222 3.488 0.000
L1.Tirol 0.039901 0.034249 1.165 0.244
L1.Vorarlberg 0.086180 0.031078 2.773 0.006
L1.Wien -0.058002 0.067179 -0.863 0.388
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.514055 0.136356 3.770 0.000
L1.Burgenland 0.060599 0.069822 0.868 0.385
L1.Kärnten 0.015830 0.059400 0.266 0.790
L1.Niederösterreich -0.016725 0.159991 -0.105 0.917
L1.Oberösterreich 0.137639 0.142292 0.967 0.333
L1.Salzburg 0.061035 0.075497 0.808 0.419
L1.Steiermark 0.122817 0.101835 1.206 0.228
L1.Tirol 0.210135 0.068090 3.086 0.002
L1.Vorarlberg 0.023324 0.061787 0.377 0.706
L1.Wien -0.119292 0.133559 -0.893 0.372
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184329 0.097173 1.897 0.058
L1.Burgenland -0.020193 0.049758 -0.406 0.685
L1.Kärnten -0.006657 0.042331 -0.157 0.875
L1.Niederösterreich 0.075378 0.114016 0.661 0.509
L1.Oberösterreich 0.404534 0.101402 3.989 0.000
L1.Salzburg -0.019292 0.053802 -0.359 0.720
L1.Steiermark -0.013514 0.072572 -0.186 0.852
L1.Tirol 0.182121 0.048524 3.753 0.000
L1.Vorarlberg 0.046249 0.044032 1.050 0.294
L1.Wien 0.174443 0.095179 1.833 0.067
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.246153 0.127091 1.937 0.053
L1.Burgenland 0.042236 0.065078 0.649 0.516
L1.Kärnten -0.038188 0.055364 -0.690 0.490
L1.Niederösterreich -0.047531 0.149120 -0.319 0.750
L1.Oberösterreich -0.062086 0.132623 -0.468 0.640
L1.Salzburg 0.056364 0.070367 0.801 0.423
L1.Steiermark 0.397430 0.094916 4.187 0.000
L1.Tirol 0.462693 0.063464 7.291 0.000
L1.Vorarlberg 0.154526 0.057588 2.683 0.007
L1.Wien -0.209224 0.124484 -1.681 0.093
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124559 0.152473 0.817 0.414
L1.Burgenland 0.019790 0.078075 0.253 0.800
L1.Kärnten -0.072379 0.066421 -1.090 0.276
L1.Niederösterreich 0.190674 0.178902 1.066 0.287
L1.Oberösterreich -0.004718 0.159110 -0.030 0.976
L1.Salzburg 0.254163 0.084421 3.011 0.003
L1.Steiermark 0.140742 0.113872 1.236 0.216
L1.Tirol 0.050049 0.076138 0.657 0.511
L1.Vorarlberg 0.063758 0.069090 0.923 0.356
L1.Wien 0.236930 0.149345 1.586 0.113
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.577212 0.081453 7.086 0.000
L1.Burgenland -0.036114 0.041709 -0.866 0.387
L1.Kärnten -0.012566 0.035483 -0.354 0.723
L1.Niederösterreich 0.001463 0.095571 0.015 0.988
L1.Oberösterreich 0.294121 0.084998 3.460 0.001
L1.Salzburg 0.017000 0.045099 0.377 0.706
L1.Steiermark 0.005053 0.060832 0.083 0.934
L1.Tirol 0.077922 0.040674 1.916 0.055
L1.Vorarlberg 0.120196 0.036909 3.257 0.001
L1.Wien -0.037696 0.079782 -0.472 0.637
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137474 0.049050 0.197718 0.249484 0.065873 0.128168 -0.037694 0.168665
Kärnten 0.137474 1.000000 0.004073 0.194655 0.165735 -0.118868 0.151880 0.009619 0.315036
Niederösterreich 0.049050 0.004073 1.000000 0.286166 0.077791 0.221977 0.154788 0.049006 0.364918
Oberösterreich 0.197718 0.194655 0.286166 1.000000 0.294836 0.285693 0.101381 0.068993 0.131345
Salzburg 0.249484 0.165735 0.077791 0.294836 1.000000 0.145614 0.056790 0.087576 -0.011515
Steiermark 0.065873 -0.118868 0.221977 0.285693 0.145614 1.000000 0.115342 0.118814 -0.105987
Tirol 0.128168 0.151880 0.154788 0.101381 0.056790 0.115342 1.000000 0.183550 0.157597
Vorarlberg -0.037694 0.009619 0.049006 0.068993 0.087576 0.118814 0.183550 1.000000 0.024118
Wien 0.168665 0.315036 0.364918 0.131345 -0.011515 -0.105987 0.157597 0.024118 1.000000